package zozopo.warehouse.report;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.flow.comm.Flow;
import zozopo.flow.comm.FlowCode;
import zozopo.flow.operations.FlowTB;
import zozopo.flow.operations.RecordlistOS;
import zozopo.flow.operations.RecordlistTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.ReceiptOS;
import zozopo.warehouse.operations.ReceiptTB;
import zozopo.warehouse.operations.ReceiptlistOS;
import zozopo.warehouse.operations.ReceiptlistTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ReceiptlistReportAction extends ActionSupport implements Action,SessionAware{
	private String limitedCode = "REPORT.RECEIPTLIST";
	
	//传入参数
	private String searchStr = "";
	private double profitValue = 0.0;
	//分页参数
	private int beginPageNum = 0;
	private int pageSize = 20;
	private int rowNum = 0;
	
	//传出参数
	private List<ReceiptlistTB> receiptlistList;
	private Map<Integer,RecordlistTB> flowRecordlistMap;
	private Map<String,FlowTB> flowMap;
	
	private Map<Integer,List<ReceiptTB>> receiptListMap;
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		ReceiptlistOS receiptlistOS = new ReceiptlistOS();
		
		RecordlistOS recordlistOS = new RecordlistOS(receiptlistOS.getConn());
		ReceiptOS receiptOS = new ReceiptOS(receiptlistOS.getConn());
		
		//flowMap = flow.getFlowCodeMapByKind(FlowCode.HOUSEWARE_RECEIPTLIST);
		
		
		receiptlistList = receiptlistOS.selectForReport(profitValue,beginPageNum, pageSize);
		rowNum = receiptlistOS.getRowNumForReport(profitValue);
		
		
		
		String inStr = "(";
		boolean isFirst = true;
		
		if(receiptlistList == null){
			return null;
		}
		
		for(ReceiptlistTB receiptlist:receiptlistList){
			if(isFirst){
				inStr += receiptlist.getId_receiptlist();
				isFirst = false;
			}else{
				inStr += "," + receiptlist.getId_receiptlist();
			}
		}
		inStr +=")";
		
		
		flowRecordlistMap = recordlistOS.getRecordlistMapByKindForReport(receiptlistList);
		receiptListMap = receiptOS.getReceiptidListMap(inStr);
		
		receiptlistOS.releaseConnection();
		
		return SUCCESS;
		
	}
	
	
	
	
	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有权限.");
			return;
		}
		
	}

	public String getSearchStr() {
		return searchStr;
	}
	public void setSearchStr(String searchStr) {
		this.searchStr = searchStr;
	}
	public int getBeginPageNum() {
		return beginPageNum;
	}
	public void setBeginPageNum(int beginPageNum) {
		this.beginPageNum = beginPageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getRowNum() {
		return rowNum;
	}
	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}
	public List<ReceiptlistTB> getReceiptlistList() {
		return receiptlistList;
	}
	public void setReceiptlistList(List<ReceiptlistTB> receiptlistList) {
		this.receiptlistList = receiptlistList;
	}
	public Map<Integer, RecordlistTB> getFlowRecordlistMap() {
		return flowRecordlistMap;
	}
	public void setFlowRecordlistMap(Map<Integer, RecordlistTB> flowRecordlistMap) {
		this.flowRecordlistMap = flowRecordlistMap;
	}
	public Map<String, FlowTB> getFlowMap() {
		return flowMap;
	}
	public void setFlowMap(Map<String, FlowTB> flowMap) {
		this.flowMap = flowMap;
	}
	public Map<Integer, List<ReceiptTB>> getReceiptListMap() {
		return receiptListMap;
	}
	public void setReceiptListMap(Map<Integer, List<ReceiptTB>> receiptListMap) {
		this.receiptListMap = receiptListMap;
	}
	public double getProfitValue() {
		return profitValue;
	}
	public void setProfitValue(double profitValue) {
		this.profitValue = profitValue;
	}

}
